package com.whmnx.my.ui.viewmodel;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;

import com.whmnx.base.bean.AddressBean;
import com.whmnx.my.R;
import com.whmnx.my.ui.fragment.MyAddLoctionFragment;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.RxBus;

/**
 * author : huang
 * date   : 2020/9/15 0015 18:44
 * version: 1.0
 * @author Administrator
 */
public class LoctionItemViewModel extends ItemViewModel {
    public ObservableField<AddressBean> entity = new ObservableField<>();
    public ObservableField<String> Address_Label = new ObservableField<>("");
    public ObservableField<String> Address_N = new ObservableField<>("");

    public ObservableInt viewVisibility = new ObservableInt(View.GONE);
    public ObservableInt viewVisibility2 = new ObservableInt(View.GONE);
    public ObservableInt viewVisibility3 = new ObservableInt(View.VISIBLE);
    private AddressBean addressBean;
    public Drawable drawableImg;

    public LoctionItemViewModel(@NonNull LoctionModel viewModel, AddressBean addressBean) {
        super(viewModel);
        this.addressBean = addressBean;
        this.entity.set(addressBean);
        Address_N.set((String) addressBean.getAddress_Name().subSequence(0,1));
        if (TextUtils.isEmpty(addressBean.getAddress_LabelDetail())){
            Address_Label.set(addressBean.getAddress_Detailed() + " ");
        }else {
            Address_Label.set(addressBean.getAddress_Detailed() + " " + addressBean.getAddress_LabelDetail());
        }
        if (entity.get().getAddress_State() == 0){
            viewVisibility.set(View.VISIBLE);
            drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), R.color.appColor);
        }else {
            drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), R.color.textColorGray);
            viewVisibility.set(View.GONE);
        }
    }




    public BindingCommand OnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putSerializable("addressBean",addressBean);
            viewModel.startContainerActivity(MyAddLoctionFragment.class.getCanonicalName(),bundle);
        }
    });
    public BindingCommand OnClickCommand2 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            RxBus.getDefault().post(addressBean);
            viewModel.finish();
        }
    });
}
